package com.byapp.fast.common.converter;

import com.byapp.fast.common.enums.PlayDescEnum;
import com.byapp.fast.common.utils.EnumUtils;
import com.byapp.fast.modules.contract.dto.AddPlayDTO;
import com.byapp.fast.modules.contract.dto.BetItemsDTO;
import com.byapp.fast.modules.match.entity.MatchOddsEntity;
import com.byapp.fast.modules.match.entity.MatchRefEntity;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

public class AddPlayDTOConverter {

    public static AddPlayDTO create(MatchOddsEntity matchOddsEntity,
                                    MatchRefEntity matchRefEntity) {
        AddPlayDTO addPlayDTO = new AddPlayDTO();

        // 获取玩法赔率详情
        List<BetItemsDTO> betItemsDTOS = BetItemsDTOConverter.mapToTarget(matchOddsEntity, matchRefEntity);

        String id = String.valueOf(matchOddsEntity.getId());
        String playId = matchOddsEntity.getPlayId();
        String handicap = matchOddsEntity.getHandicap();
        String betStatus = matchOddsEntity.getBetStatus();
        String matchId = matchOddsEntity.getMatchId();

        PlayDescEnum codeEnum = EnumUtils.getByCode(Integer.parseInt(playId), PlayDescEnum.class);

        addPlayDTO.setPlayId(id)
                .setLid(matchId)
                .setPlayCode(playId)
                .setHandicap(handicap)
                .setStatus(betStatus)
                .setBetItems(betItemsDTOS)
                .setPlaydesc(codeEnum != null ? codeEnum.getMsg() : null);

        return addPlayDTO;
    }
}
